## Covid-19 and Jharkhand Analysis
## Author: Carlos F. Gould
## Date: August 2021
## Purpose: Analyze new data 

# Libraries ----

library(tidyverse)
library(readxl)
library(openxlsx)
library(lubridate)
library(haven)
library(arsenal)
library(cowplot)
library(ggstatsplot)
library(ggsci)

mycontrols  <- tableby.control(test=TRUE, total=FALSE,
                               numeric.stats=c("N", "meansd", "medianq1q3", "range", "Nmiss"),
                               cat.stats=c("countpct", "Nmiss"),
                               stats.labels=list(N='Count', meansd='Mean (SD)', medianq1q3='Median (IQR)'),
                               digits = 2L,
                               digits.pct = 0L)

# open data here ------
jcovid_full_b_1 <- read_csv("~/Dropbox/Jharkhand-COVID19/Data/jcovid_full_b_1.csv")

# 0. Some processing variables ------

jcovid_full_b_2 <- jcovid_full_b_1 %>% 
  mutate(B_primary_lpg = ifelse(B_q_84_primary_cookfuel==5, 1, 0),
         B_secondary_lpg = ifelse(B_q_84_primary_cookfuel!=5 &
                                    B_q_87_has_lpg==1, 1, 0),
         B_primary_polluting = ifelse(B_q_84_primary_cookfuel!=5, 1, 0),
         B_secondary_polluting = ifelse(((B_q_84_primary_cookfuel==5) & 
                                          (B_q_90_use_firewood_chips==1 |
                                          B_q_91_use_dung==1 |
                                          B_q_92_use_ag_residue==1 |
                                          B_q_93_use_coal==1)), 1, 0), 
         
         W_primary_lpg = ifelse(d_2_primary_cook_fuel==9, 1, 0),
         W_primary_polluting = ifelse(((d_2_primary_cook_fuel>=1 & 
                                      d_2_primary_cook_fuel<=6) |
                                      d_2_primary_cook_fuel==8), 1, 0),
         W_secondary_lpg = ifelse(d_2_primary_cook_fuel!=9 &
                                    d_1_9_any_cook_fuel_lpg==1, 1, 0),
         W_secondary_polluting = ifelse(((d_2_primary_cook_fuel>=9 |
                                           d_2_primary_cook_fuel==7) & 
                                        (d_1_1_firewood==1 |
                                           d_1_2_any_cook_fuel_agresidue==1 |
                                           d_1_3_any_cook_fuel_dung==1 |
                                           d_1_4_any_cook_fuel_charcoal==1 |
                                           d_1_5_any_cook_fuel_coal==1 |
                                           d_1_6_any_cook_fuel_kerosene==1 |
                                           d_1_8_any_cook_fuel_gasoline==1)), 1, 0),
         
         W_kerosene_lighting = ifelse(d_0_1_primary_lighting_fourdays==2 |
                                        d_0_all_lighting_kerosene==1, 1, 0)) %>% 
  mutate(B_no_polluting = ifelse(B_q_90_use_firewood_chips==0 &
                                   B_q_91_use_dung==0 &
                                   B_q_92_use_ag_residue==0 &
                                   B_q_93_use_coal==0, 1, 0), 
         B_no_lpg = ifelse(B_q_87_has_lpg==0, 1, 0), 
         
         W_no_lpg = ifelse(W_primary_lpg==0 & W_secondary_lpg==0, 1, 0),
         W_no_polluting = ifelse(W_primary_polluting==0 & W_secondary_polluting==0, 1, 0)) %>% 
  mutate(W_cookfuel_stack_category = ifelse(W_primary_polluting==1 & W_no_lpg==1, "Exclusive polluting", 
                                            ifelse(W_primary_polluting==1 & W_secondary_lpg==1, "Primary polluting, Secondary LPG", 
                                                   ifelse(W_primary_lpg==1 & W_secondary_polluting==1, "Primary LPG, Secondary polluting", 
                                                          ifelse(W_primary_lpg==1 & W_no_polluting==1, "Exclusive LPG", NA)))),
         B_cookfuel_stack_category = ifelse(B_primary_polluting==1 & B_no_lpg==1, "Exclusive polluting", 
                                            ifelse(B_primary_polluting==1 & B_secondary_lpg==1, "Primary polluting, Secondary LPG", 
                                                   ifelse(B_primary_lpg==1 & B_secondary_polluting==1, "Primary LPG, Secondary polluting", 
                                                          ifelse(B_primary_lpg==1 & B_no_polluting==1, "Exclusive LPG", NA)))),
  ) %>% 
  # Any COVID-related economic impacts? 
  mutate(
    weekly_econ_hardship_any = ifelse(c_1_1_econ_hardship_difficulty_food=="1" | 
                                      c_1_2_econ_hardship_increase_prices=="1" | 
                                      c_1_3_econ_hardship_reduced_income=="1" | 
                                      c_1_4_econ_hardship_salary_employment_loss=="1" | 
                                      c_1_5_econ_hardship_hourly_employment_loss=="1" | 
                                      c_1_6_econ_hardship_hourly_employment_reduced=="1" | 
                                      c_1_7_econ_hardship_other_cash_sources_reduced=="1" | 
                                      c_1_8_econ_hardship_unable_tolook_employment=="1", 1, 0),
    weekly_econ_hardship_job_money = ifelse(c_1_3_econ_hardship_reduced_income=="1" | 
                                              c_1_4_econ_hardship_salary_employment_loss=="1" | 
                                              c_1_5_econ_hardship_hourly_employment_loss=="1" | 
                                              c_1_6_econ_hardship_hourly_employment_reduced=="1" | 
                                              c_1_7_econ_hardship_other_cash_sources_reduced=="1" | 
                                              c_1_8_econ_hardship_unable_tolook_employment=="1", 1, 0),
  ) %>% 
  # Any use of three free cylinders?
  arrange(hhid, round) %>% 
  group_by(hhid) %>% 
  mutate(
    free_cylinder_total = h_4_1_obtained_free_cylinder_number,
    free_cylinder_total_lag1 = lag(h_4_1_obtained_free_cylinder_number, 1),
    free_cylinder_total_lag2 = lag(h_4_1_obtained_free_cylinder_number, 2),
    free_cylinder_total_lag3 = lag(h_4_1_obtained_free_cylinder_number, 3),
    free_cylinder_total_lag4 = lag(h_4_1_obtained_free_cylinder_number, 4),
    free_cylinder_total_lag5 = lag(h_4_1_obtained_free_cylinder_number, 5)
  ) %>% 
  ungroup() %>% 
  mutate(
    free_cylinder_change_lag1 = free_cylinder_total - free_cylinder_total_lag1,
    free_cylinder_change_lag2 = free_cylinder_total - free_cylinder_total_lag2,
    free_cylinder_change_lag3 = free_cylinder_total - free_cylinder_total_lag3,
    free_cylinder_change_lag4 = free_cylinder_total - free_cylinder_total_lag4,
    free_cylinder_change_lag5 = free_cylinder_total - free_cylinder_total_lag5) %>% 
  mutate(free_cylinder_change = ifelse(!is.na(free_cylinder_change_lag1), free_cylinder_change_lag1,
                                       ifelse(!is.na(free_cylinder_change_lag2), free_cylinder_change_lag2,
                                              ifelse(!is.na(free_cylinder_change_lag3), free_cylinder_change_lag3,
                                                     ifelse(!is.na(free_cylinder_change_lag4), free_cylinder_change_lag4,
                                                            ifelse(!is.na(free_cylinder_change_lag5), free_cylinder_change_lag5, NA)))))) %>% 
  group_by(hhid, b_1_relation_to_hhead) %>% 
  mutate(free_cylinder_aware = h_1_threecylinder_aware,
         free_cylinder_aware_lag1 = lag(h_1_threecylinder_aware, 1),
         free_cylinder_aware_lag2 = lag(h_1_threecylinder_aware, 2),
         free_cylinder_aware_lag3 = lag(h_1_threecylinder_aware, 3),
         free_cylinder_aware_lag4 = lag(h_1_threecylinder_aware, 4),
         free_cylinder_aware_lag5 = lag(h_1_threecylinder_aware, 5)) %>% 
  ungroup() %>% 
  mutate(
    free_cylinder_aware_change_lag1 = free_cylinder_aware - free_cylinder_aware_lag1,
    free_cylinder_aware_change_lag2 = free_cylinder_aware - free_cylinder_aware_lag2,
    free_cylinder_aware_change_lag3 = free_cylinder_aware - free_cylinder_aware_lag3,
    free_cylinder_aware_change_lag4 = free_cylinder_aware - free_cylinder_aware_lag4,
    free_cylinder_aware_change_lag5 = free_cylinder_aware - free_cylinder_aware_lag5
  ) %>% 
  mutate(free_cylinder_aware_change = ifelse(!is.na(free_cylinder_aware_change_lag1), free_cylinder_aware_change_lag1,
                                             ifelse(!is.na(free_cylinder_aware_change_lag2), free_cylinder_aware_change_lag2,
                                                    ifelse(!is.na(free_cylinder_aware_change_lag3), free_cylinder_aware_change_lag3,
                                                           ifelse(!is.na(free_cylinder_aware_change_lag4), free_cylinder_aware_change_lag4,
                                                                  ifelse(!is.na(free_cylinder_aware_change_lag5), free_cylinder_aware_change_lag5, NA)))))) 
  



tmp <- jcovid_full_b_2 %>% dplyr::select(hhid, round, b_1_relation_to_hhead, h_1_threecylinder_aware, h_4_1_obtained_free_cylinder_number, free_cylinder_total, free_cylinder_total_lag1, free_cylinder_change_lag1, free_cylinder_change_lag2,free_cylinder_change)
view(tmp)

# Timing of surveys ---------

round_date_range <- jcovid_full_b_2 %>% 
  group_by(round) %>% 
  summarize(first_date = min(date_interview, na.rm=T),
            last_date = max(date_interview, na.rm=T),
            n=n())


# Establish baseline energy patterns ------

baseline_primary_hhenergy <- tableby(~ as.factor(B_q_57_primary_lighting) + 
                                       as.factor(B_q_59_primary_lighting_satisfaction) + 
                                       as.factor(B_q_58_primary_lighting_meetsneeds) + 
                                       as.factor(B_q_58_primary_lighting_isexpensive) + 
                                       as.factor(B_q_58_primary_lighting_issafe) + 
                                       as.factor(B_q_58_primary_lighting_isreliable) + 
                                       
                                       as.factor(B_q_60_grid_electricity) + 
                                       B_q_60_grid_electricity_years + 
                                       as.factor(B_q_60_grid_electricity_saubhagya) + 
                                       B_q_60_grid_electricity_cnxn_fee + 
                                       B_q_60_grid_electricity_monthly_fee + 
                                       
                                       as.factor(B_q_61_microgrid_electricity) + 
                                       as.factor(B_q_62_solar_system) + 
                                       as.factor(B_q_63_solar_lantern) + 
                                       
                                       as.factor(B_q_64_kerosene_lighting) + 
                                       B_q_64_kerosene_lantern_number +
                                       B_q_64_kerosene_wicklamp_number + 
                                       B_q_64_kerosene_lighting_hours + 
                                    as.factor(B_q_64_kerosene_lighting_health_effect) + 
                                      
                                      as.factor(B_q_73_electrification) + 
                                      B_q_74_electrification_hrs_available +
                                      as.factor(B_q_80_electrification_satisfied) + 
                                      as.factor(B_q_80_electrification_unsatisfied_expensive) + 
                                      as.factor(B_q_80_electrification_unsatisfied_unavailable) + 
                                      as.factor(B_q_80_electrification_unsatisfied_poorquality) + 
                                      as.factor(B_q_80_electrification_unsatisfied_poormaintenance) + 
                                      
                                       as.factor(B_q_84_primary_cookfuel) + 
                                      B_q_85_cook_meals_daily + 
                                      B_q_86_cook_hrs_daily +
                                      
                                      as.factor(B_q_87_has_lpg) + 
                                      as.factor(B_q_87_lpg_pmuy) + 
                                      B_q_87_lpg_connection + 
                                      
                                      as.factor(B_q_87_lpg_allneeds) + 
                                      as.factor(B_q_87_lpg_allneeds_no_expensive) + 
                                      as.factor(B_q_87_lpg_allneeds_no_freebiomassavail) + 
                                      as.factor(B_q_87_lpg_allneeds_no_preferchulhasome) +
                                      as.factor(B_q_87_lpg_allneeds_no_dontlikelpgfood) + 
                                      as.factor(B_q_87_lpg_allneeds_no_lpgavailabilityconstraint) + 
                                      B_q_87_large_lpg_cyls + 
                                      B_q_87_large_lpg_cyls_cost_dist + 
                                      B_q_87_large_lpg_cyls_cost_market + 
                                      B_q_87_small_lpg_cyls + 
                                      B_q_87_small_lpg_cyls_cost_dist + 
                                      B_q_87_small_lpg_cyls_cost_market + 
                                      
                                      as.factor(B_q_87_lpg_doorstep_deliv) + 
                                      B_q_87_lpg_oneway + 
                                      as.factor(B_q_87_lpg_satisfaction) +
                                      
                                      B_q_87_lpg_refill_order_receive_gap + 
                                      as.factor(B_q_87_lpg_refill_who_orders) + 
                                      as.factor(B_q_87_lpg_refill_subsidy_who_acct) +
                                      as.factor(B_q_87_lpg_refill_who_gets) + 
                                      
                                      as.factor(B_q_90_use_firewood_chips) + 
                                      as.factor(B_q_90_collect_firewood_forest) + 
                                      as.factor(B_q_90_collect_firewood_roadside) + 
                                      as.factor(B_q_90_collect_firewood_farm) +
                                      
                                      B_q_90_firewood_collect_freq + 
                                      B_q_90_firewood_collect_hrs_trip + 
                                      B_q_90_firewood_collect_km_trip + 
                                      
                                      as.factor(B_q_91_use_dung) + 
                                      as.factor(B_q_92_use_ag_residue) + 
                                      as.factor(B_q_93_use_coal) + 
                                      as.factor(B_q_97_primary_cookstove_satisfaction)
                                      
                                      
                                      
                                      ,
                                     data = jcovid_full_b_2 %>% 
                                       distinct(hhid, .keep_all = T), 
                                     control = mycontrols)


# arsenal::write2word(summary(baseline_primary_hhenergy), "~/Dropbox/Jharkhand-COVID19/Code/tables/baseline_primary_hhenergy.doc")


# Establish shifts in baseline and current cooking patterns  ------

# Overall by primary polluting at baseline
summary_stack_prim_cook <- tableby(B_primary_polluting ~ 
                                     as.factor(d_0_1_primary_lighting_fourdays) + 
                                     as.factor(d_0_all_lighting_grid) + 
                                     as.factor(d_0_all_lighting_kerosene) +
                                     as.factor(d_2_primary_cook_fuel) + 
                                     as.factor(d_1_1_firewood) + 
                                     as.factor(d_1_2_any_cook_fuel_agresidue) + 
                                     as.factor(d_1_3_any_cook_fuel_dung) + 
                                     as.factor(d_1_9_any_cook_fuel_lpg),
                                   jcovid_full_b_2, 
                                   control = mycontrols)

summary(summary_stack_prim_cook)

# arsenal::write2word(summary(summary_stack_prim_cook), "~/Dropbox/Jharkhand-COVID19/Code/tables/summary_stack_prim_cook.doc")

# Overall by primary polluting at baseline and by round
summary_stack_prim_cook_round_polluting <- tableby(round ~ 
                                     as.factor(d_0_1_primary_lighting_fourdays) + 
                                     as.factor(d_0_all_lighting_grid) + 
                                     as.factor(d_0_all_lighting_kerosene) + 
                                       as.factor(d_2_primary_cook_fuel) + 
                                     as.factor(d_1_1_firewood) + 
                                     as.factor(d_1_2_any_cook_fuel_agresidue) + 
                                     as.factor(d_1_3_any_cook_fuel_dung) + 
                                     as.factor(d_1_9_any_cook_fuel_lpg),
                                   jcovid_full_b_2, strata = B_primary_polluting,
                                   control = mycontrols)

summary(summary_stack_prim_cook_round_polluting)

# arsenal::write2word(summary(summary_stack_prim_cook_round_polluting), "~/Dropbox/Jharkhand-COVID19/Code/tables/summary_stack_prim_cook_round_polluting.doc")




# 4. Establish covid-related parameters ------

# 4.1 Hardships -------
ever_covid_hardships_df <- jcovid_full_b_2 %>% 
  group_by(hhid) %>% 
  summarize(econ_hardship_difficulty_food = mean(c_1_1_econ_hardship_difficulty_food=="1", na.rm=T),
            econ_hardship_increase_prices = mean(c_1_2_econ_hardship_increase_prices=="1", na.rm=T),
            econ_hardship_reduced_income = mean(c_1_3_econ_hardship_reduced_income=="1", na.rm=T),
            econ_hardship_salary_employment_loss = mean(c_1_4_econ_hardship_salary_employment_loss=="1", na.rm=T),
            econ_hardship_hourly_employment_loss = mean(c_1_5_econ_hardship_hourly_employment_loss=="1", na.rm=T),
            econ_hardship_hourly_employment_reduced = mean(c_1_6_econ_hardship_hourly_employment_reduced=="1", na.rm=T),
            econ_hardship_other_cash_sources_reduced = mean(c_1_7_econ_hardship_other_cash_sources_reduced=="1", na.rm=T),
            econ_hardship_unable_tolook_employment = mean(c_1_8_econ_hardship_unable_tolook_employment=="1", na.rm=T),
            hh_size_fewer = mean(c_2_hh_size_change==1, na.rm=T),
            hh_size_same = mean(c_2_hh_size_change==2, na.rm=T),
            hh_size_more = mean(c_2_hh_size_change==3, na.rm=T)) %>% 
  # ungroup() %>% 
  mutate(econ_hardship_difficulty_food = ifelse(econ_hardship_difficulty_food>0, 1, 0),
         econ_hardship_increase_prices = ifelse(econ_hardship_increase_prices>0, 1, 0),
         econ_hardship_reduced_income = ifelse(econ_hardship_reduced_income>0, 1, 0),
         econ_hardship_salary_employment_loss = ifelse(econ_hardship_salary_employment_loss>0, 1, 0),
         econ_hardship_hourly_employment_loss = ifelse(econ_hardship_hourly_employment_loss>0, 1, 0),
         econ_hardship_hourly_employment_reduced = ifelse(econ_hardship_hourly_employment_reduced>0, 1, 0),
         econ_hardship_other_cash_sources_reduced = ifelse(econ_hardship_other_cash_sources_reduced>0, 1, 0),
         econ_hardship_unable_tolook_employment = ifelse(econ_hardship_unable_tolook_employment>0, 1, 0),
         hh_size_fewer = ifelse(hh_size_fewer>0, 1, 0),
         hh_size_same = ifelse(hh_size_same>0, 1, 0),
         hh_size_more = ifelse(hh_size_more>0, 1, 0)) %>% 
  summarize(econ_hardship_difficulty_food = mean(econ_hardship_difficulty_food, na.rm=T),
            econ_hardship_increase_prices = mean(econ_hardship_increase_prices, na.rm=T),
            econ_hardship_reduced_income = mean(econ_hardship_reduced_income, na.rm=T),
            econ_hardship_salary_employment_loss = mean(econ_hardship_salary_employment_loss, na.rm=T),
            econ_hardship_hourly_employment_loss = mean(econ_hardship_hourly_employment_loss, na.rm=T),
            econ_hardship_hourly_employment_reduced = mean(econ_hardship_hourly_employment_reduced, na.rm=T),
            econ_hardship_other_cash_sources_reduced = mean(econ_hardship_other_cash_sources_reduced, na.rm=T),
            econ_hardship_unable_tolook_employment = mean(econ_hardship_unable_tolook_employment, na.rm=T),
            hh_size_fewer = mean(hh_size_fewer, na.rm=T),
            hh_size_same = mean(hh_size_same, na.rm=T),
            hh_size_more = mean(hh_size_more, na.rm=T)) %>% 
  mutate(round = "Ever Reported") %>% 
  pivot_longer(-round,"parameter", "value")
  
  


covid_hardships_df <- jcovid_full_b_2 %>% 
  group_by(round) %>% 
  summarize(econ_hardship_difficulty_food = mean(c_1_1_econ_hardship_difficulty_food=="1", na.rm=T),
            econ_hardship_increase_prices = mean(c_1_2_econ_hardship_increase_prices=="1", na.rm=T),
            econ_hardship_reduced_income = mean(c_1_3_econ_hardship_reduced_income=="1", na.rm=T),
            econ_hardship_salary_employment_loss = mean(c_1_4_econ_hardship_salary_employment_loss=="1", na.rm=T),
            econ_hardship_hourly_employment_loss = mean(c_1_5_econ_hardship_hourly_employment_loss=="1", na.rm=T),
            econ_hardship_hourly_employment_reduced = mean(c_1_6_econ_hardship_hourly_employment_reduced=="1", na.rm=T),
            econ_hardship_other_cash_sources_reduced = mean(c_1_7_econ_hardship_other_cash_sources_reduced=="1", na.rm=T),
            econ_hardship_unable_tolook_employment = mean(c_1_8_econ_hardship_unable_tolook_employment=="1", na.rm=T),
            hh_size_fewer = mean(c_2_hh_size_change==1, na.rm=T),
            hh_size_same = mean(c_2_hh_size_change==2, na.rm=T),
            hh_size_more = mean(c_2_hh_size_change==3, na.rm=T)) %>% 
  pivot_longer(-round,"parameter", "value") %>% 
  bind_rows(ever_covid_hardships_df) %>% 
  mutate(parameter = plyr::mapvalues(parameter,
                                     from=c("econ_hardship_difficulty_food", "econ_hardship_increase_prices",
                                            "econ_hardship_reduced_income", "econ_hardship_salary_employment_loss",
                                            "econ_hardship_hourly_employment_loss", "econ_hardship_hourly_employment_reduced",
                                            "econ_hardship_other_cash_sources_reduced", "econ_hardship_unable_tolook_employment",
                                            "hh_size_fewer", "hh_size_same",
                                            "hh_size_more"),
                                     to=c("Increased difficulty accessing food for household", "Increased prices for necessary goods",
                                          "Reduced income from any form of economic activity", "Loss of salaried employment",
                                          "Loss of hourly waged employment,\nor loss of daily waged employment", "Reduced hours of employment,\nor reduced days of waged employment",
                                          "Reduced cash from any other sources\nsuch as family members outside household or government", "Unable to look for employment,\nsuch as going to a town for seasonal labor",
                                          "Fewer people live in household now", "Same number of people in household now",
                                          "More people live in household now"))) %>% 
  mutate(parameter = factor(parameter, levels=c("Increased difficulty accessing food for household", "Increased prices for necessary goods",
                                                "Reduced income from any form of economic activity", "Loss of salaried employment",
                                                "Loss of hourly waged employment,\nor loss of daily waged employment", "Reduced hours of employment,\nor reduced days of waged employment",
                                                "Reduced cash from any other sources\nsuch as family members outside household or government", "Unable to look for employment,\nsuch as going to a town for seasonal labor",
                                                "Fewer people live in household now", "Same number of people in household now",
                                                "More people live in household now")),
         round = factor(round, levels = c("Round 1", "Round 2", "Round 3", "Round 4",
                                          "Round 5", "Round 6", "Ever Reported")))




  

covid_hardships <- tableby(round ~ 
                             as.factor(c_1_1_econ_hardship_difficulty_food) + 
                             as.factor(c_1_2_econ_hardship_increase_prices) +
                             as.factor(c_1_3_econ_hardship_reduced_income) + 
                             as.factor(c_1_4_econ_hardship_salary_employment_loss) + 
                             as.factor(c_1_5_econ_hardship_hourly_employment_loss) + 
                             as.factor(c_1_6_econ_hardship_hourly_employment_reduced) + 
                             as.factor(c_1_7_econ_hardship_other_cash_sources_reduced) + 
                             as.factor(c_1_8_econ_hardship_unable_tolook_employment) + 
                             as.factor(c_2_hh_size_change),
                             jcovid_full_b_2, 
                             control = mycontrols)

summary(covid_hardships)

# arsenal::write2word(summary(covid_hardships), "~/Dropbox/Jharkhand-COVID19/Code/tables/august2021/covid_hardships.doc")


# 5 Using energy differently ------

# Self reported ------

ever_covid_energy_change_df <- jcovid_full_b_2 %>% 
  group_by(hhid) %>% 
  summarize(kerosene_use_less = mean(d_0_3_1_kerosene_use_compare=="3", na.rm=T),
            kerosene_use_same = mean(d_0_3_1_kerosene_use_compare=="2", na.rm=T),
            kerosene_use_more = mean(d_0_3_1_kerosene_use_compare=="1", na.rm=T),
            
            kerosene_hours_less = mean(d_0_3_2_kerosene_use_compare_hours=="3", na.rm=T),
            kerosene_hours_same = mean(d_0_3_2_kerosene_use_compare_hours=="2", na.rm=T),
            kerosene_hours_more = mean(d_0_3_2_kerosene_use_compare_hours=="1", na.rm=T),
            
            cook_hours_less = mean(d_8_1_cook_hours_compare_inlockdown=="3", na.rm=T),
            cook_hours_same = mean(d_8_1_cook_hours_compare_inlockdown=="2", na.rm=T),
            cook_hours_more = mean(d_8_1_cook_hours_compare_inlockdown=="1", na.rm=T),
            
            cook_recall_hours_less = mean(d_8_2_cook_hours_compare_recalllockdown=="3", na.rm=T),
            cook_recall_hours_same = mean(d_8_2_cook_hours_compare_recalllockdown=="2", na.rm=T),
            cook_recall_hours_more = mean(d_8_2_cook_hours_compare_recalllockdown=="1", na.rm=T),
            
            lpg_less = mean(d_9_lpg_use_compare=="2", na.rm=T),
            lpg_same = mean(d_9_lpg_use_compare=="3", na.rm=T),
            lpg_more = mean(d_9_lpg_use_compare=="1", na.rm=T),
            
            polluting_less = mean(d_10_pollutingfuel_use_compare=="2", na.rm=T),
            polluting_same = mean(d_10_pollutingfuel_use_compare=="3", na.rm=T),
            polluting_more = mean(d_10_pollutingfuel_use_compare=="1", na.rm=T),
            
            biomass_collect_less_freq = mean(f_1_firewood_compare_collect_freq_inlockdown=="3", na.rm=T),
            biomass_collect_same_freq = mean(f_1_firewood_compare_collect_freq_inlockdown=="2", na.rm=T),
            biomass_collect_more_freq = mean(f_1_firewood_compare_collect_freq_inlockdown=="1", na.rm=T),
            
            biomass_collect_less_amt = mean(f_2_firewood_compare_collect_amt_inlockdown=="3", na.rm=T),
            biomass_collect_same_amt = mean(f_2_firewood_compare_collect_amt_inlockdown=="2", na.rm=T),
            biomass_collect_more_amt = mean(f_2_firewood_compare_collect_amt_inlockdown=="1", na.rm=T),
            
            biomass_store_less_amt = mean(f_3_firewood_compare_reserve_amt_inlockdown=="3", na.rm=T),
            biomass_store_same_amt = mean(f_3_firewood_compare_reserve_amt_inlockdown=="2", na.rm=T),
            biomass_store_more_amt = mean(f_3_firewood_compare_reserve_amt_inlockdown=="1", na.rm=T),
            
            biomass_collect_ease_harder = mean(f_3_firewood_compare_reserve_amt_inlockdown=="3", na.rm=T),
            biomass_collect_ease_same = mean(f_3_firewood_compare_reserve_amt_inlockdown=="2", na.rm=T),
            biomass_collect_ease_easier = mean(f_3_firewood_compare_reserve_amt_inlockdown=="1", na.rm=T),
            ) %>% 
  # ungroup() %>% 
  mutate(kerosene_use_less = ifelse(kerosene_use_less>0, 1, 0),
         kerosene_use_same = ifelse(kerosene_use_same>0, 1, 0),
         kerosene_use_more = ifelse(kerosene_use_more>0, 1, 0),
         
         kerosene_hours_less = ifelse(kerosene_hours_less>0, 1, 0),
         kerosene_hours_same = ifelse(kerosene_hours_same>0, 1, 0),
         kerosene_hours_more = ifelse(kerosene_hours_more>0, 1, 0),
         
         cook_hours_less = ifelse(cook_hours_less>0, 1, 0),
         cook_hours_same = ifelse(cook_hours_same>0, 1, 0),
         cook_hours_more = ifelse(cook_hours_more>0, 1, 0),
         
         cook_recall_hours_less = ifelse(cook_recall_hours_less>0, 1, 0),
         cook_recall_hours_same = ifelse(cook_recall_hours_same>0, 1, 0),
         cook_recall_hours_more = ifelse(cook_recall_hours_more>0, 1, 0),
         
         lpg_less = ifelse(lpg_less>0, 1, 0),
         lpg_same = ifelse(lpg_same>0, 1, 0),
         lpg_more = ifelse(lpg_more>0, 1, 0),
         
         polluting_less = ifelse(polluting_less>0, 1, 0),
         polluting_same = ifelse(polluting_same>0, 1, 0),
         polluting_more = ifelse(polluting_more>0, 1, 0),
         
         biomass_collect_less_freq = ifelse(biomass_collect_less_freq>0, 1, 0),
         biomass_collect_same_freq = ifelse(biomass_collect_same_freq>0, 1, 0),
         biomass_collect_more_freq = ifelse(biomass_collect_more_freq>0, 1, 0),
         
         biomass_collect_less_amt = ifelse(biomass_collect_less_amt>0, 1, 0),
         biomass_collect_same_amt = ifelse(biomass_collect_same_amt>0, 1, 0),
         biomass_collect_more_amt = ifelse(biomass_collect_more_amt>0, 1, 0),
         
         biomass_store_less_amt = ifelse(biomass_store_less_amt>0, 1, 0),
         biomass_store_same_amt = ifelse(biomass_store_same_amt>0, 1, 0),
         biomass_store_more_amt = ifelse(biomass_store_more_amt>0, 1, 0),
         
         biomass_collect_ease_harder = ifelse(biomass_collect_ease_harder>0, 1, 0),
         biomass_collect_ease_same = ifelse(biomass_collect_ease_same>0, 1, 0),
         biomass_collect_ease_easier = ifelse(biomass_collect_ease_easier>0, 1, 0)) %>% 
  summarize(kerosene_use_less = mean(kerosene_use_less, na.rm=T),
            kerosene_use_same = mean(kerosene_use_same, na.rm=T),
            kerosene_use_more = mean(kerosene_use_more, na.rm=T),
            
            kerosene_hours_less = mean(kerosene_hours_less, na.rm=T),
            kerosene_hours_same = mean(kerosene_hours_same, na.rm=T),
            kerosene_hours_more = mean(kerosene_hours_more, na.rm=T),
            
            cook_hours_less = mean(cook_hours_less, na.rm=T),
            cook_hours_same = mean(cook_hours_same, na.rm=T),
            cook_hours_more = mean(cook_hours_more, na.rm=T),
            
            cook_recall_hours_less = mean(cook_recall_hours_less, na.rm=T),
            cook_recall_hours_same = mean(cook_recall_hours_same, na.rm=T),
            cook_recall_hours_more = mean(cook_recall_hours_more, na.rm=T),
            
            lpg_less = ifelse(lpg_less>0, 1, 0),
            lpg_same = ifelse(lpg_same>0, 1, 0),
            lpg_more = ifelse(lpg_more>0, 1, 0),
            
            polluting_less = mean(polluting_less, na.rm=T),
            polluting_same = mean(polluting_same, na.rm=T),
            polluting_more = mean(polluting_more, na.rm=T),
            
            biomass_collect_less_freq = mean(biomass_collect_less_freq, na.rm=T),
            biomass_collect_same_freq = mean(biomass_collect_same_freq, na.rm=T),
            biomass_collect_more_freq = mean(biomass_collect_more_freq, na.rm=T),
            
            biomass_collect_less_amt = mean(biomass_collect_less_amt, na.rm=T),
            biomass_collect_same_amt = mean(biomass_collect_same_amt, na.rm=T),
            biomass_collect_more_amt = mean(biomass_collect_more_amt, na.rm=T),
            
            biomass_store_less_amt = mean(biomass_store_less_amt, na.rm=T),
            biomass_store_same_amt = mean(biomass_store_same_amt, na.rm=T),
            biomass_store_more_amt = mean(biomass_store_more_amt, na.rm=T),
            
            biomass_collect_ease_harder = mean(biomass_collect_ease_harder, na.rm=T),
            biomass_collect_ease_same = mean(biomass_collect_ease_same, na.rm=T),
            biomass_collect_ease_easier = mean(biomass_collect_ease_easier, na.rm=T)) %>% 
  mutate(round = "Ever Reported") %>% 
  pivot_longer(-round,"parameter", "value")




covid_energy_change_df <- jcovid_full_b_2 %>% 
  group_by(round) %>% 
  summarize(kerosene_use_less = mean(d_0_3_1_kerosene_use_compare=="3", na.rm=T),
            kerosene_use_same = mean(d_0_3_1_kerosene_use_compare=="2", na.rm=T),
            kerosene_use_more = mean(d_0_3_1_kerosene_use_compare=="1", na.rm=T),
            
            kerosene_hours_less = mean(d_0_3_2_kerosene_use_compare_hours=="3", na.rm=T),
            kerosene_hours_same = mean(d_0_3_2_kerosene_use_compare_hours=="2", na.rm=T),
            kerosene_hours_more = mean(d_0_3_2_kerosene_use_compare_hours=="1", na.rm=T),
            
            cook_hours_less = mean(d_8_1_cook_hours_compare_inlockdown=="3", na.rm=T),
            cook_hours_same = mean(d_8_1_cook_hours_compare_inlockdown=="2", na.rm=T),
            cook_hours_more = mean(d_8_1_cook_hours_compare_inlockdown=="1", na.rm=T),
            
            cook_recall_hours_less = mean(d_8_2_cook_hours_compare_recalllockdown=="3", na.rm=T),
            cook_recall_hours_same = mean(d_8_2_cook_hours_compare_recalllockdown=="2", na.rm=T),
            cook_recall_hours_more = mean(d_8_2_cook_hours_compare_recalllockdown=="1", na.rm=T),
            
            lpg_less = mean(d_9_lpg_use_compare=="2", na.rm=T),
            lpg_same = mean(d_9_lpg_use_compare=="3", na.rm=T),
            lpg_more = mean(d_9_lpg_use_compare=="1", na.rm=T),
            
            polluting_less = mean(d_10_pollutingfuel_use_compare=="2", na.rm=T),
            polluting_same = mean(d_10_pollutingfuel_use_compare=="3", na.rm=T),
            polluting_more = mean(d_10_pollutingfuel_use_compare=="1", na.rm=T),
            
            biomass_collect_less_freq = mean(f_1_firewood_compare_collect_freq_inlockdown=="3", na.rm=T),
            biomass_collect_same_freq = mean(f_1_firewood_compare_collect_freq_inlockdown=="2", na.rm=T),
            biomass_collect_more_freq = mean(f_1_firewood_compare_collect_freq_inlockdown=="1", na.rm=T),
            
            biomass_collect_less_amt = mean(f_2_firewood_compare_collect_amt_inlockdown=="3", na.rm=T),
            biomass_collect_same_amt = mean(f_2_firewood_compare_collect_amt_inlockdown=="2", na.rm=T),
            biomass_collect_more_amt = mean(f_2_firewood_compare_collect_amt_inlockdown=="1", na.rm=T),
            
            biomass_store_less_amt = mean(f_3_firewood_compare_reserve_amt_inlockdown=="3", na.rm=T),
            biomass_store_same_amt = mean(f_3_firewood_compare_reserve_amt_inlockdown=="2", na.rm=T),
            biomass_store_more_amt = mean(f_3_firewood_compare_reserve_amt_inlockdown=="1", na.rm=T),
            
            biomass_collect_ease_harder = mean(f_3_firewood_compare_reserve_amt_inlockdown=="3", na.rm=T),
            biomass_collect_ease_same = mean(f_3_firewood_compare_reserve_amt_inlockdown=="2", na.rm=T),
            biomass_collect_ease_easier = mean(f_3_firewood_compare_reserve_amt_inlockdown=="1", na.rm=T),
  ) %>% 
  pivot_longer(-round,"parameter", "value") %>% 
  bind_rows(ever_covid_energy_change_df) %>% 
  mutate(variable = plyr::mapvalues(parameter,
                                     from=c("kerosene_use_less", "kerosene_use_same", "kerosene_use_more",
                                            "kerosene_hours_less", "kerosene_hours_same", "kerosene_hours_more",
                                            
                                            "cook_hours_less", "cook_hours_same", "cook_hours_more",
                                            "cook_recall_hours_less", "cook_recall_hours_same", "cook_recall_hours_more",
                                            
                                            "lpg_less", "lpg_same", "lpg_more",
                                            "polluting_less", "polluting_same", "polluting_more",
                                            
                                            "biomass_collect_less_freq", "biomass_collect_same_freq", "biomass_collect_more_freq",
                                            "biomass_collect_less_amt", "biomass_collect_same_amt", "biomass_collect_more_amt",
                                            "biomass_collect_ease_harder", "biomass_collect_ease_same", "biomass_collect_ease_easier",
                                            "biomass_store_less_amt", "biomass_store_same_amt", "biomass_store_more_amt"),
                                     to=c("Kerosene use: overall", "Kerosene use: overall", "Kerosene use: overall",
                                          "Kerosene use: hours", "Kerosene use: hours", "Kerosene use: hours",
                                          
                                          "Cook hours", "Cook hours", "Cook hours",
                                          "Cook hours (recall)", "Cook hours (recall)", "Cook hours (recall)",
                                          
                                          "LPG use: overall", "LPG use: overall", "LPG use: overall", 
                                          "Polluting fuel use: overall", "Polluting fuel use: overall", "Polluting fuel use: overall", 
                                          
                                          "Biomass collection frequency", "Biomass collection frequency", "Biomass collection frequency", 
                                          "Biomass collection amount", "Biomass collection amount", "Biomass collection amount", 
                                          "Biomass collection difficulty", "Biomass collection difficulty", "Biomass collection difficulty", 
                                          "Biomass reserve amount", "Biomass reserve amount", "Biomass reserve amount")),
         change = plyr::mapvalues(parameter,
                                    from=c("kerosene_use_less", "kerosene_use_same", "kerosene_use_more",
                                           "kerosene_hours_less", "kerosene_hours_same", "kerosene_hours_more",
                                           
                                           "cook_hours_less", "cook_hours_same", "cook_hours_more",
                                           "cook_recall_hours_less", "cook_recall_hours_same", "cook_recall_hours_more",
                                           
                                           "lpg_less", "lpg_same", "lpg_more",
                                           "polluting_less", "polluting_same", "polluting_more",
                                           
                                           "biomass_collect_less_freq", "biomass_collect_same_freq", "biomass_collect_more_freq",
                                           "biomass_collect_less_amt", "biomass_collect_same_amt", "biomass_collect_more_amt",
                                           "biomass_collect_ease_harder", "biomass_collect_ease_same", "biomass_collect_ease_easier",
                                           "biomass_store_less_amt", "biomass_store_same_amt", "biomass_store_more_amt"),
                                    to=c("Less", "Same", "More",
                                         "Less", "Same", "More",
                                         
                                         "Less", "Same", "More",
                                         "Less", "Same", "More",
                                         
                                         "Less", "Same", "More",
                                         "Less", "Same", "More",
                                         
                                         "Less", "Same", "More",
                                         "Less", "Same", "More",
                                         "More", "Same", "Less",
                                         "Less", "Same", "More"))) %>% 
  mutate(variable = factor(variable, levels=c("Kerosene use: overall", 
                                              "Kerosene use: hours", 
                                              
                                              "Cook hours", 
                                              "Cook hours (recall)", 
                                              
                                              "LPG use: overall", 
                                              "Polluting fuel use: overall", 
                                              
                                              "Biomass collection frequency",
                                              "Biomass collection amount", 
                                              "Biomass collection difficulty",
                                              "Biomass reserve amount")),
         change = factor(change, levels= c("More", "Same", "Less")),
         round = factor(round, levels = rev(c("Round 1", "Round 2", "Round 3", "Round 4",
                                          "Round 5", "Round 6", "Ever Reported"))))



# Table ------
covid_energy_reasons <- tableby(round ~ 
                          d_0_2_1_1_not_used_kerosene_nofuel + 
                          d_0_2_1_2_not_used_kerosene_conservingfuel + 
                          d_0_2_1_3_not_used_kerosene_unablebuy + 
                          d_0_2_1_4_not_used_kerosene_notgoodlight + 
                          d_0_2_1_5_not_used_kerosene_unsafe + 
                          d_0_2_1_6_not_used_kerosene_hasbetter + 
                          d_0_2_1_7_not_used_kerosene_broken + 
                          
                          # as.factor(d_0_3_1_kerosene_use_compare) +
                          # as.factor(d_0_3_2_kerosene_use_compare_hours) + 
                          
                          d_3_1_1_not_used_lpg_nofuel + 
                          d_3_1_2_not_used_lpg_conservingfuel + 
                          d_3_1_3_not_used_lpg_notcookusualdishes + 
                          d_3_1_4_not_used_lpg_otherfuels + 
                          d_3_1_5_not_used_lpg_notlikenow + 
                          d_3_1_6_not_used_lpg_fearful + 
                          d_3_1_7_not_used_lpg_usualcookisnotcook + 
                          d_3_1_8_not_used_lpg_broken
                        
                          ,
                           jcovid_full_b_2, 
                           control = mycontrols)

summary(covid_energy_reasons)

# arsenal::write2word(summary(covid_energy_reasons), "~/Dropbox/Jharkhand-COVID19/Code/tables/august2021/covid_energy_reasons.doc")





# 7. Three free cylinder policy parameters -------

# Aware at first survey
three_cyl_first_aware <- jcovid_full_b_2 %>% 
  select(hhid, round, h_1_threecylinder_aware, h_2_threecylinder_aware_how) %>% 
  arrange(hhid, round) %>% 
  group_by(hhid) %>% 
  mutate(n=row_number()) %>%
  ungroup() %>% 
  filter(n==1) 

table(three_cyl_first_aware$h_1_threecylinder_aware)
table(three_cyl_first_aware$h_2_threecylinder_aware_how)
            
  
three_cyl_ever_reported_df <- jcovid_full_b_2 %>% 
  group_by(hhid) %>% 
  summarize(aware = mean(h_1_threecylinder_aware=="1", na.rm=T),
            
            aware_distributor = mean(h_2_threecylinder_aware_how=="1", na.rm=T),
            aware_neighbor = mean(h_2_threecylinder_aware_how=="2", na.rm=T),
            aware_omc = mean(h_2_threecylinder_aware_how=="3", na.rm=T),
            aware_text = mean(h_2_threecylinder_aware_how=="4", na.rm=T),
            aware_newspaper = mean(h_2_threecylinder_aware_how=="5", na.rm=T),
            aware_tv = mean(h_2_threecylinder_aware_how=="6", na.rm=T),
            aware_radio = mean(h_2_threecylinder_aware_how=="7", na.rm=T),
            
            subsidy_deposited = mean(h_3_lpg_refill_subsidy_deposited=="1", na.rm=T),
            
            free_cylinder = mean(h_4_obtained_free_cylinder=="1", na.rm=T),
            num_free_cylinder = max(h_4_1_obtained_free_cylinder_number, na.rm=T),
            
            convenience_same = mean(h_4_2_free_cylinder_process_convenience=="1", na.rm=T),
            convenience_easier = mean(h_4_2_free_cylinder_process_convenience=="2", na.rm=T),
            convenience_harder = mean(h_4_2_free_cylinder_process_convenience=="3", na.rm=T),
            
            convenience_harder_fullprice = mean(h_4_2_1_process_difficult_fullpriceatsale=="1", na.rm=T),
            convenience_harder_longgetsubsidy = mean(h_4_2_2_process_difficult_longgetsubsidy=="1", na.rm=T),
            convenience_harder_moredifficultrefill = mean(h_4_2_2_process_difficult_moredifficultrefill=="1", na.rm=T),
            convenience_harder_policyconfusion = mean(h_4_2_2_process_difficult_policyconfusionatsale=="1", na.rm=T)
  ) %>% 
  # ungroup() %>% 
  mutate(aware = ifelse(aware>0, 1, 0),
         
         aware_distributor = ifelse(aware_distributor>0, 1, 0),
         aware_neighbor = ifelse(aware_neighbor>0, 1, 0),
         aware_omc = ifelse(aware_omc>0, 1, 0),
         aware_text = ifelse(aware_text>0, 1, 0),
         aware_newspaper = ifelse(aware_newspaper>0, 1, 0),
         aware_tv = ifelse(aware_tv>0, 1, 0),
         aware_radio = ifelse(aware_radio>0, 1, 0),
         
         subsidy_deposited = ifelse(subsidy_deposited>0, 1, 0),
         
         free_cylinder = ifelse(free_cylinder>0, 1, 0),
         # num_free_cylinder = max(num_free_cylinder, na.rm=T),
         
         convenience_same = ifelse(convenience_same>0, 1, 0),
         convenience_easier = ifelse(convenience_easier>0, 1, 0),
         convenience_harder = ifelse(convenience_harder>0, 1, 0),
         
         convenience_harder_fullprice = ifelse(convenience_harder_fullprice>0, 1, 0),
         convenience_harder_longgetsubsidy = ifelse(convenience_harder_longgetsubsidy>0, 1, 0),
         convenience_harder_moredifficultrefill = ifelse(convenience_harder_moredifficultrefill>0, 1, 0),
         convenience_harder_policyconfusion = ifelse(convenience_harder_policyconfusion>0, 1, 0)) %>% 
  summarize(aware = mean(aware, na.rm=T),
            
            aware_distributor = mean(aware_distributor, na.rm=T),
            aware_neighbor = mean(aware_neighbor, na.rm=T),
            aware_omc = mean(aware_omc, na.rm=T),
            aware_text = mean(aware_text, na.rm=T),
            aware_newspaper = mean(aware_newspaper, na.rm=T),
            aware_tv = mean(aware_tv, na.rm=T),
            aware_radio = mean(aware_radio, na.rm=T),
            
            subsidy_deposited = mean(subsidy_deposited, na.rm=T),
            
            free_cylinder = mean(free_cylinder, na.rm=T),
            num_free_cylinder_zero = mean(num_free_cylinder=="-Inf", na.rm=T),
            num_free_cylinder_one = mean(num_free_cylinder==1, na.rm=T),
            num_free_cylinder_two = mean(num_free_cylinder==2, na.rm=T),
            num_free_cylinder_three = mean(num_free_cylinder==3, na.rm=T),
            num_free_cylinder_four = mean(num_free_cylinder==4, na.rm=T),
            num_free_cylinder_five = mean(num_free_cylinder==5, na.rm=T),
            
            convenience_same = mean(convenience_same, na.rm=T),
            convenience_easier = mean(convenience_easier, na.rm=T),
            convenience_harder = mean(convenience_harder, na.rm=T),
            
            convenience_harder_fullprice = mean(convenience_harder_fullprice, na.rm=T),
            convenience_harder_longgetsubsidy = mean(convenience_harder_longgetsubsidy, na.rm=T),
            convenience_harder_moredifficultrefill = mean(convenience_harder_moredifficultrefill, na.rm=T),
            convenience_harder_policyconfusion = mean(convenience_harder_policyconfusion, na.rm=T)) %>% 
  mutate(round = "Ever Reported") %>% 
  pivot_longer(-round,"parameter", "value")

# Round by round table ------
three_cyl_round <- tableby(round ~ 
                                 as.factor(h_1_threecylinder_aware) + 
                             as.factor(h_2_threecylinder_aware_how) + 
                             as.factor(h_3_lpg_refill_subsidy_deposited) + 
                             as.factor(h_4_obtained_free_cylinder) + 
                             as.factor(h_4_1_obtained_free_cylinder_number) + 
                             h_4_1_obtained_free_cylinder_number +    
                             as.factor(h_4_2_free_cylinder_process_convenience) +
                             as.factor(h_4_2_1_process_difficult_fullpriceatsale) + 
                             as.factor(h_4_2_2_process_difficult_longgetsubsidy) + 
                             as.factor(h_4_2_2_process_difficult_moredifficultrefill) + 
                             as.factor(h_4_2_2_process_difficult_policyconfusionatsale)
                             
                                ,
                                jcovid_full_b_2, 
                                control = mycontrols)

summary(three_cyl_round)

# arsenal::write2word(summary(three_cyl_round), "~/Dropbox/Jharkhand-COVID19/Code/tables/three_cyl_round.doc")



# 8. fuel preferences across rounds -------

gas_preferences_rounds <- tableby(round ~
                                     as.character(g_1_lpg_refill_cost_compare_inlockdown) + 
                                     as.character(g_1_lpg_refill_cost_compare_reaclllockdown) + 
                                    
                                     as.character(g_2_lpg_refill_difficulty_inlockdown) + 
                                     
                                    as.character(g_3_1_like_using_lpg_more) + 
                                     as.character(g_3_1_1_like_using_lpg_more_valuefastcooking) + 
                                     as.character(g_3_1_2_like_using_lpg_more_cheapernow) + 
                                     as.character(g_3_1_3_like_using_lpg_more_accessiblenow) + 
                                     as.character(g_3_1_4_like_using_lpg_more_threecylpolicy) + 
                                     as.character(g_3_1_5_like_using_lpg_more_lessbiomassnow) + 
                                     as.character(g_3_1_6_like_using_lpg_more_biomassacquireharder) + 
                                     as.character(g_3_1_7_like_using_lpg_more_tastepreferenceforlpg) + 
                                     as.character(g_3_1_8_like_using_lpg_more_tastepreferenceawayfirewood) + 
                                    as.character(g_3_1_9_like_using_lpg_more_prefercooklpg) + 
                                    as.character(g_3_1_10_like_using_lpg_more_awaycookfirewood) + 
                                    
                                    as.character(g_3_2_1_like_using_lpg_less_morecostly) + 
                                    as.character(g_3_2_2_like_using_lpg_less_lessaccessible) + 
                                    as.character(g_3_2_3_like_using_lpg_less_morebiomassnow) + 
                                    as.character(g_3_2_4_like_using_lpg_less_tastepreferenceforfirewood) + 
                                    as.character(g_3_2_5_like_using_lpg_less_tastepreferenceawaylpg) + 
                                    as.character(g_3_2_6_like_using_lpg_less_prefercookfirewood) + 
                                    as.character(g_3_2_7_like_using_lpg_less_awaycooklpg)
                                  ,
                                  jcovid_full_b_2, 
                                  control = mycontrols)

summary(gas_preferences_rounds)

# arsenal::write2word(summary(gas_preferences_rounds), "~/Dropbox/Jharkhand-COVID19/Code/tables/gas_preferences_rounds.doc")

# 9. Fuel acquisition practices across rounds -------

fuel_acquisition_rounds <- tableby(round ~
                                    as.character(e_1_1_refill_lpg_inlockdown) + 
                                    as.character(e_1_2_refill_lpg_recalllockdown) + 
                                    
                                    as.numeric(e_2_refill_lpg_wksago) + 
                                     as.numeric(e_8_refill_next_wks) +
                                    as.character(e_3_refill_source) + 
                                     
                                    as.character(e_4_1_refill_differences_nodelivery) + 
                                    as.character(e_4_2_refill_differences_deliverynow) + 
                                    as.character(e_4_3_refill_differences_longerwait) + 
                                    as.character(e_4_5_refill_differences_pickupfurther) + 
                                    as.character(e_4_6_refill_differences_pickupcloser) + 
                                    as.character(e_4_7_refill_differences_none) + 
                                     
                                    as.character(e_5_subsidy_time_compare) + 
                                    as.numeric(e_6_lpgrefill_cost) + 
                                     
                                    as.character(e_7_1_nolpg_refill_didnotrunout) + 
                                    as.character(e_7_2_nolpg_refill_rationed) + 
                                    
                                    as.character(e_7_3_nolpg_refill_nomoney) + 
                                    as.character(e_7_4_nolpg_refill_didnotwanttoleave) + 
                                    as.character(e_7_5_nolpg_refill_deliveryunavailable) + 
                                    as.character(e_7_6_nolpg_refill_couldnotleave) + 
                                    
                                      
                                    as.character(f_1_firewood_compare_collect_freq_inlockdown) + 
                                    as.character(f_2_firewood_compare_collect_amt_inlockdown) + 
                                     as.character(f_3_firewood_compare_reserve_amt_inlockdown) + 
                                     as.character(f_4_firewood_compare_collect_difficulty_inlockdown) + 
                                     as.character(f_5_firewood_compare_collect_freq_recalllockdown) + 
                                     as.character(f_6_firewood_compare_collect_amt_recalllockdown) + 
                                     as.character(f_7_firewood_compare_reserve_amt_recalllockdown) + 
                                     as.character(f_8_firewood_compare_collect_amt_recalllockdown) + 
                                     f_9_firewood_collect_last_days + 
                                     f_10_firewood_collect_next_days + 
                                     as.character(f_11_coal_compare_collect_freq_inlockdown) + 
                                     as.character(f_12_coal_compare_collect_amt_inlockdown) + 
                                     as.character(f_13_coal_collect_location_inlockdown) + 
                                     as.character(f_13_1_1_nocoal_havefuel) + 
                                     as.character(f_13_1_2_nocoal_notusing) + 
                                     as.character(f_13_1_3_nocoal_nomoney) + 
                                     as.character(f_13_1_4_nocoal_didnotwanttoleave) + 
                                     as.character(f_13_1_5_nocoal_normalspotunavailable)
                                  ,
                                  jcovid_full_b_2, 
                                  control = mycontrols)

summary(fuel_acquisition_rounds)

# arsenal::write2word(summary(fuel_acquisition_rounds), "~/Dropbox/Jharkhand-COVID19/Code/tables/fuel_acquisition_rounds.doc")

